/*
 * Copyright 2009 Lukasz Wozniak
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * you may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 *
 * http://www.apache.org/licenses/LICENSE-2.0 
 *
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and 
 * limitations under the License.
 */
package pl.sind.blip.entities;

import java.text.ParseException;
import java.util.Date;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author Lukasz Wozniak
 *
 */
public class Update extends Entity {
	
	private Long id;
	private Date createdAt;
	private Transport transport;
	private String body;
	private String type;
	private String userPath;
	private String picturesPath;
	private String recordingPath;
	private String moviePath;
	private User user;

	public Update() {
		super();
	}

	public Update(Long id, Date createdAt, Transport transport, String body,
			String type, String userPath, String picturesPath,
			String recordingPath, String moviePath) {
		super();
		this.id = id;
		this.createdAt = createdAt;
		this.transport = transport;
		this.body = body;
		this.type = type;
		this.userPath = userPath;
		this.picturesPath = picturesPath;
		this.recordingPath = recordingPath;
		this.moviePath = moviePath;
	}

	public Update(JSONObject jsonObject) throws JSONException {
		id = jsonObject.optLong("id");
		try {
			createdAt = stringToDate(jsonObject.optString("created_at"));
		} catch (ParseException e) {
			//just ignore for now
		}
		if(jsonObject.has("transport")){
			transport = new Transport(jsonObject.getJSONObject("transport"));
		}
		body = jsonObject.optString("body");
		type = jsonObject.optString("type");
		userPath = jsonObject.optString("user_path");
		if (jsonObject.optJSONObject("user") != null) {
			user = new User(jsonObject.optJSONObject("user"));
		}
		picturesPath = jsonObject.optString("pictures_path");
		recordingPath = jsonObject.optString("recording_path");
		moviePath = jsonObject.optString("movie_path");
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Date getCreatedAt() {
		return createdAt;
	}

	public void setCreatedAt(Date createdAt) {
		this.createdAt = createdAt;
	}

	public Transport getTransport() {
		return transport;
	}

	public void setTransport(Transport transport) {
		this.transport = transport;
	}

	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getUserPath() {
		return userPath;
	}

	public void setUserPath(String userPath) {
		this.userPath = userPath;
	}

	public String getPicturesPath() {
		return picturesPath;
	}

	public void setPicturesPath(String picturesPath) {
		this.picturesPath = picturesPath;
	}

	public String getRecordingPath() {
		return recordingPath;
	}

	public void setRecordingPath(String recordingPath) {
		this.recordingPath = recordingPath;
	}

	public String getMoviePath() {
		return moviePath;
	}

	public void setMoviePath(String moviePath) {
		this.moviePath = moviePath;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	@Override
	public String toString() {
		StringBuilder b = new StringBuilder();
		b.append(Status.class.getName()).append("{");
		b.append("id: ").append(id);
		b.append(", createdAt: ").append(dateToString(createdAt));
		b.append(", transport: ").append(transport);
		b.append(", body: ").append(body);
		b.append(", type: ").append(type);
		b.append(", userPath: ").append(userPath);
		b.append(", user: ").append(user);
		b.append(", picturesPath: ").append(picturesPath);
		b.append(", recordingPath: ").append(recordingPath);
		b.append(", moviePath: ").append(moviePath);
		b.append("}");
		return b.toString();
	}
	
	
}
